from django.conf.urls.defaults import *
from django.utils.translation import ugettext as _

from settings import ADMIN_BASE_URL

import views
from models import Image, Folder
from common import Info

urlpatterns = patterns('djips_common',
 		       (r'^synchronize/(?P<folder_id>-?\d+)/$',
			'views.synchronize'),
 		       (r'^synchronize/$', 'views.synchronize'),
		       (r'^images/$', 'views.manage_images'),
 		       (r'^images/(?P<folder_id>-?\d+)/$',
			'views.manage_images'),
		       (r'^languages/$', 'views.manage_languages'),
 		       (r'^image/(?P<image_id>\d+)/$',
			'views.manage_image'),
 		       (r'^colors/$', 'views.manage_colors'),
                       (r'^colors/delete/(?P<color_id>\d+)/$',
                         'views.delete_color'),
 		       (r'^translations/', 'views.manage_translations'),
		       (r'^ajax/delete_color_msg/(?P<color_id>\d+)/$',
			 'ajax_views.show_delete_color_message'),
		       (r'^ajax/delete_color/(?P<color_id>\d+)/$',
			 'ajax_views.delete_color'),
		       (r'^ajax/images_ui/$', 'ajax_views.images_ui'),
		       (r'^ajax/get_images/(?P<folder_id>\d+)/$',
			 'ajax_views.get_images'),
		       (r'^ajax/get_full_image_url/(?P<image_id>\d+)/$',
			 'ajax_views.get_full_image_url'),
		       (r'^ajax/get_image_properties_form/(?P<image_id>\d+)/$',
			 'ajax_views.get_image_properties_form'),
		       (r'^ajax/save_image_properties/(?P<image_id>\d+)/$',
			 'ajax_views.save_image_properties'),
		       (r'^ajax/spray/(?P<image_id>\d+)/$',
			 'ajax_views.spray'),
		       (r'^$', 'views.index')
		       )

menu_title = _("Common")

def make_infos():
    """ Returns a list of Info objects used in Dashboard.

    For djips_common, we only return one Info displaying some statistics.
    """

    nb_images = len(Image.objects.all())
    nb_folders = len(Folder.objects.all())

    info = Info(title="Djips common statistics",
		text = "You have %s images in %s folders" % \
		(nb_images, nb_folders))
		

    return [info]

def make_menu():
    """ Returns a list of couples (title, url) used to build administration
    menu.
    """
    base_url=  ADMIN_BASE_URL + '/djips_common/'

    return [(_('Synchronize filesystem'), base_url + 'synchronize/'),
	    (_('Images'), base_url + 'images/'),
	    (_('Categories'), base_url + 'colors/'),
	    (_('Translations'), base_url + 'translations/'),
	    (_('Languages'), base_url + 'languages/')]
